#-*-coding:GBK-*-
import tkinter as tk
import tkinter.messagebox
from MainPage import MainPage


# 一张画纸
class LoginPage(object):
    def __init__(self, master=None):
        self.root = master
        self.root.geometry('%dx%d' % (500, 280))
        self.username = tk.StringVar()
        self.password = tk.StringVar()
        self.page = tk.Frame(self.root)
        l2 = tk.Label(self.page)
        l2.grid(row=1, column=0)
        choose2 = [("教师登录", 0), ("管理员登录", 2)]
        get_choose2 = tk.IntVar()
        for i, num in choose2:
            b = tk.Radiobutton(self.page, text=i, variable=get_choose2, value=num)
            b.grid(row=5, column=num)
        # 将控件布局到 root 对象 （GUI 程序对象）
        self.page.pack()
        self.create_page()

    def create_page(self):
        """
            使用表格布局绘制内容

        """
        tk.Label(self.page).grid(row=0, stick=tk.W)
        tk.Label(self.page, text='账户: ').grid(row=1, stick=tk.W, pady=10)
        tk.Entry(self.page, textvariable=self.username).grid(row=1, column=1, stick=tk.E)
        tk.Label(self.page, text='密码: ').grid(row=2, stick=tk.W, pady=10)
        tk.Entry(self.page, textvariable=self.password, show='*').grid(row=2, column=1, stick=tk.E)
        tk.Button(self.page, text='登陆', command=self.login_check).grid(row=3, stick=tk.W, pady=10)
        tk.Button(self.page, text='退出', command=self.page.quit).grid(row=3, column=1, stick=tk.E)

    def login_check(self):
        """登录检测"""
        name = self.username.get()
        secret = self.password.get()
        if name == 'admin' and secret == '123456':
            self.page.destroy()
            MainPage(self.root)
        else:
            tkinter.messagebox.showinfo(title='错误', message='账号或密码错误！')


if __name__ == '__main__':
    root = tk.Tk()
    LoginPage(root)

    root.mainloop()